/**
 * 
 */
package jp.ddo.trismegistos.timer.logic;

import java.text.DecimalFormat;
import java.util.TimerTask;

import android.os.Handler;
import android.widget.TextView;

/**
 * 
 * @author y_sugasawa
 * @author $Author: aigis.developer@gmail.com $
 * @version $Rev: 41 $ $Date: 2011-09-26 15:42:24 +0000 (Mon, 26 Sep 2011) $
 * 
 */
public class CountupTask extends TimerTask {

	private Handler handler;

	private TextView countupView;

	private double time;

	private DecimalFormat df = new DecimalFormat();

	/**
	 * 
	 * @param handler
	 * @param countupView
	 */
	public CountupTask(final Handler handler, final TextView countupView,
			final DecimalFormat df) {
		this.handler = handler;
		this.countupView = countupView;
		this.df = df;
		time = 0.000d;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void run() {
		handler.post(new Runnable() {
			public void run() {
				time += 0.001d;
				countupView.setText(df.format(time));
			}
		});
	}

	public double getTime() {
		return time;
	}

}
